<?php
/*
 * Author: Quan Van Sinh
 * Email: sinhvnb@vietnambiz.com
 */
checkLoginHeader();
checkPermission();
photosAction();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Images manager</title>
    
    <script type="text/javascript" src="/admin/themes/default/js/jquery.min.js"></script>
    <script type="text/javascript" src="/admin/themes/default/js/jquery.MultiFile.pack.js"></script>
    <script type="text/javascript" src="/admin/themes/default/js/jquery.tabs.min.js"></script>
    <script type="text/javascript">
        $(function() {
            $('#photo-tabs').tabs({ fxShow: { height: 'show', opacity: 'show' }, fxSpeed: 'normal' });
    <?php
        if($_SESSION['rsMessages']!=''){
    ?>
            setTimeout("closeResultMessages()",5000);
    <?php
        }
    ?>
        });
        function closeResultMessages(){
            $('#rsMessages').hide("slow");
        }
        function returnToParent(src){
            place = '<?php echo $_GET['place'];?>';
            if(place!=''){
                if(place=='description'){
                    window.opener.document.getElementById('src').value = src;
                    window.opener.document.getElementById('alt').value = src;
                }else if(place=='image'){
                    window.opener.document.getElementById('image').value = src;
                    window.opener.document.getElementById('imgDisplay').src = src;
                }
                window.close();
            }else{
                return false;
            }
        }
    </script>
    <link rel="stylesheet" href="/admin/themes/default/css/jquery.tabs.css" type="text/css" media="print, projection, screen" />
    <style type="text/css" media="screen, projection">
        .error{
            color:red;
            font-weight:bold;
        }
        .success{
            color: green;
            font-weight:bold;
        }
    </style>
</head>

<body>
    
    <div>
        <div id="photo-tabs">
            <ul>
                <li><a href="#photo-manage"><span>Manage images</span></a></li>
                <li><a href="#photo-add"><span>Add images</span></a></li>
            </ul>
            <div id="photo-manage">
                <div id="rsMessages" style="text-align: left;"><? if(isset($_SESSION['rsMessages'])){echo $_SESSION['rsMessages']; $_SESSION['rsMessages']='';} ?></div>
                <?php
                    $imageDir = 'uploads/articles/';
                    if($_GET['dir']!=''){
                        $imageDir = $_GET['dir'];
                    }
                    $arrDir = explode('/', $imageDir);
                    for($i=1;$i<count($arrDir)-1;$i++){
                        if($i==1){
                            echo '<a style="margin-right: 12px" href="?dir=uploads/'.$arrDir[$i].'/&place='.$_GET['place'].'">ROOT</a>';
                        }elseif($i==2){
                            echo '>> <a style="margin-right: 12px" href="?dir=uploads/'.$arrDir[$i-1].'/'.$arrDir[$i].'/&place='.$_GET['place'].'">'.$arrDir[$i].'</a>';
                        }elseif($i==3){
                            echo '>> <a style="margin-right: 12px" href="?dir=uploads/'.$arrDir[$i-2].'/'.$arrDir[$i-1].'/'.$arrDir[$i].'/&place='.$_GET['place'].'">'.$arrDir[$i].'</a>';
                        }
                    }
                    echo '<br><br>';
                    
                    $pos = strpos($imageDir, 'thumb');
                    if($pos==FALSE && count($arrDir)!=5 && $_GET['place']=='image') {
                        listDir($imageDir);
                    }elseif($pos==FALSE && count($arrDir)==5 && $_GET['place']=='image'){
                        listImages($imageDir.'thumb-137-113/');
                    }elseif($pos==FALSE && count($arrDir)<5 && $_GET['place']=='description'){
                        listDir($imageDir);
                    }elseif($pos==FALSE && count($arrDir)>4 && $_GET['place']=='description'){
                        listImagesDescription($imageDir,$imageDir.'thumb-137-113/');
                    }
                ?>
            </div>
            <div id="photo-add">
                <div>
                    <form method="post" action="" id="form" name="formAddPhotos" style="padding-top: 10px" enctype="multipart/form-data">
                        <div align="left">
                            <input type="checkbox" name="duantieubieu" value="1" /> (Tạo thumb cho dự án tiêu biểu trên trang chủ.)
                        </div>
                        <div align="left">
                            Select file to upload: <input type="hidden" id="photosActionType" name="photosActionType" value="addPhotos"/>
                            <input type="file" class="multi" maxlength="10" name="photos[]" id="photos" accept="gif|jpg|jpeg|png"/><input type="submit" value="Upload photos" name="addPhotosSubmit" id="addPhotosSubmit"/>
                        </div>
                        <div id="imageList"></div>
                    </form>
                </div>
            </div>
            
        </div>
    </div>
</body>
</html>



